﻿using AiBLSmartEdu.Module.SmartEnglish.API.DTOs;
using AiBLSmartEdu.Module.SmartEnglish.API.Services;
using Domain;
using FrameworkCore;
using FrameworkCore.Controllers;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AiBLSmartEdu.Module.SmartEnglish.API.Controllers;

/// <summary>
/// 智慧英语助手
/// </summary>
public class SmartEnglishController : BaseModuleController
{
    private readonly SmartEnglishServices _smartEnglishServices;

    public SmartEnglishController(
        SmartEnglishServices smartEnglishServices)
    {
        _smartEnglishServices = smartEnglishServices;
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="filter">分页输入模型</param>
    /// <returns></returns>
    [HttpGet("Page")]
    public async Task<PageResult<VocabularyOutputModel>> Pagination([FromQuery] VocabularyPaginationFilter filter)
    {
        return await _smartEnglishServices.PageAsync(filter);
    }

    /// <summary>
    /// 创建词汇
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Result> Create(VocabularyCreateInputModel input)
    {
        await _smartEnglishServices.CreateAsync(input);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 修改状态
    /// </summary>
    /// <param name="id">唯一标识</param>
    /// <param name="status">状态</param>
    /// <returns></returns>
    [HttpPut("{id}/{status}")]
    public async Task<Result> Update(long id, LearningStatus status)
    {
        await _smartEnglishServices.UpdateStatusAsync(id, status);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 是否收藏
    /// </summary>
    /// <param name="id">唯一标识</param>
    /// <returns></returns>
    [HttpPut("Favorited/{id}")]
    public async Task<Result> IsFavorited(long id)
    {
        await _smartEnglishServices.IsFavoritedAsync(id);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 批量删除文档
    /// </summary>
    /// <returns></returns>
    [HttpDelete("{ids}")]
    public async Task<Result> BulkDeletes(string ids)
    {
        await _smartEnglishServices.DeleteAsync(ids);
        return await Result.SucceedAsync();
    }

}
